/* Copyright (c) 2007 John Wells

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameLevel.ContentPipeline.Leadwerks14
{
    /// <summary>The standard vertex used for most everything.</summary>
    /// <remarks>The AmbientOcclusion value is in the range of 0...1: 1=Not Occluded, 0=Fully Occluded.</remarks>
    public class BrushVertex : IComparable<BrushVertex>
    {
        #region Fields
        // Public fields
        public Vector3 Position, Normal;
        public Vector2 TextureCoordinate;
        public Vector3 Tangent, Binormal;
        public float AmbientOcclusion;
        public Vector2 LightmapCoordinate;
        #endregion

        #region Constructors
        public BrushVertex(Vector3 position, Vector2 textureCoordinate, Vector3 normal, Vector3 tangent, Vector3 binormal, float ambientOcclusion, Vector2 lightmapCoordinate)
        {
            this.Position = position;
            this.TextureCoordinate = textureCoordinate;
            this.Normal = normal;
            this.Tangent = tangent;
            this.Binormal = binormal;
            this.AmbientOcclusion = ambientOcclusion;
            this.LightmapCoordinate = lightmapCoordinate;
        }
        #endregion


        #region Methods
        public static bool operator ==(BrushVertex left, BrushVertex right)
        {
            // Note: I expanded out this stuff because it actually made a
            // slight difference in speed during performance profiling.
            return left.Position.X == right.Position.X &&
                left.Position.Y == right.Position.Y &&
                left.Position.Z == right.Position.Z &&
                left.TextureCoordinate.X == right.TextureCoordinate.X &&
                left.TextureCoordinate.Y == right.TextureCoordinate.Y &&
                left.Normal.X == right.Normal.X &&
                left.Normal.Y == right.Normal.Y &&
                left.Normal.Z == right.Normal.Z &&
                left.Tangent.X == right.Tangent.X &&
                left.Tangent.Y == right.Tangent.Y &&
                left.Tangent.Z == right.Tangent.Z &&
                left.Binormal.X == right.Binormal.X &&
                left.Binormal.Y == right.Binormal.Y &&
                left.Binormal.Z == right.Binormal.Z &&
                left.AmbientOcclusion == right.AmbientOcclusion;
        }

        public static bool operator !=(BrushVertex left, BrushVertex right)
        {
            return !(left == right);
        }

        public override bool Equals(object obj)
        {
            // Null objects simply cannot be equal to this instance
            if (obj == null)
                return false;

            // Sub, super, or other types are not this instance
            if (obj.GetType() != typeof(BrushVertex))
                return false;

            // Rely on the == operator defined above
            return this == (BrushVertex)obj;
        }

        public override int GetHashCode()
        {
            // Return my fakey-fake hash code
            return 3456;
        }

        public void SetPosition(Vector3 position)
        {
            this.Position = position;
        }

        #endregion

        #region IComparable<BrushVertex> Members
        int IComparable<BrushVertex>.CompareTo(BrushVertex other)
        {
            // This comparison is just for sorting purposes - it obviously sorts in 1D only
            return (int)(this.Position.X - other.Position.X);
        }
        #endregion
    } 
}
